﻿using System;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;

public class Relation : MonoBehaviour
{
    [HideInInspector]
    public bool start = false;
    [HideInInspector]
    public GameObject mTarget;
    [HideInInspector]
    public GameObject This;

    public Button btn;

    private void Start()
    {
        btn.onClick.AddListener(delegate
        {
            GameObject.Find("GameManager").GetComponent<TongXunLuManager>().SelectRelation = this.gameObject;
        });
    }
    void Update()
    {
        Vector3 targetPos = mTarget.transform.localPosition;
        Vector3 curPos = This.transform.localPosition;
        this.gameObject.transform.position = This.transform.position;
        double angle = Math.Atan2(targetPos.y - curPos.y, targetPos.x - curPos.x) * 180 / Math.PI;
        this.gameObject.GetComponent<Image>().transform.rotation = Quaternion.Euler(0, 0, (float)angle + 270);
        this.gameObject.GetComponent<Image>().rectTransform.sizeDelta = new Vector2(15, Vector3.Distance(targetPos, curPos));
    }
}
